<?php

class Encoder extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
	}
	
	function index()
	{
		$this->itemlist();
	}	
			
	function itemlist()
	{
		$data = array();
		$data['content'] = $this->load->view('encoder/list_view', $data, true);
		$data['title'] = array ( "Encoder", "Requistions", "List" );
		$this->load->view('main_view', $data);
	}
	
	function getlist($month = null, $year = null, $rr_number = null, $name = null)
	{
		$this->load->model('requisition_model', 'requisitions');
		echo json_encode($this->requisitions->get_requisitions($month, $year, $rr_number, $name));
	}
	
	function newrequisition()
	{	
		$data = array();
		
		$this->load->model('category_model', 'categories');
		$this->load->model('department_model', 'departments');
		
		$data['categories'] = $this->categories->get_categories();
		$data['departments'] = $this->departments->get_departments();
		
		$data['content'] = $this->load->view('encoder/requisition_view', $data, true);
		$data['title'] = array ( "Encoder", "Requisitions", "New" );
		$this->load->view('main_view', $data);
	}
	
	function getmaterials($name = null, $code = null)
	{
		$this->load->model('material_model', 'materials');
		echo json_encode($this->materials->get_materials($name, $code));		
	}
	
	function createrequisition()
	{
		$this->load->model('requisition_model', 'requisitions');
		$this->requisitions->create($_POST['rr_number'], $_POST['requestor_id'], $_POST['department_id'], $_POST['materials']);
	}
}